package bunny.demo.shake;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Demo_shakeActivity extends Activity
{
	private static final String TAG = "Demo_shakeActivity";
	private Shaker shaker;
	private Button btnStart, btnStop;
	private TextView resultTextView;

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		initWidgets();

		shaker = new Shaker(this);
		// shaker.showAllSensors();

		shaker.setShakerEventListenr(new ShakerEventListenr()
		{
			@Override
			public void OnShake(String result)
			{
				resultTextView.setText(result);
				shaker.stop();
			}
		});
	}

	private void initWidgets()
	{
		btnStart = (Button) findViewById(R.id.main_btn_start);
		btnStop = (Button) findViewById(R.id.main_btn_stop);
		resultTextView = (TextView) findViewById(R.id.main_text_result);

		btnStart.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				shaker.start();
			}
		});

		btnStop.setOnClickListener(new OnClickListener()
		{

			@Override
			public void onClick(View v)
			{
				shaker.stop();
			}
		});

	}

	@Override
	protected void onPause()
	{
		super.onPause();
		shaker.stop();
	}

}